package com.zoffy.zoffyapi.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zoffy.zoffyapi.annotion.AuthCheck;
import com.zoffy.zoffyapi.commen.BaseResponse;
import com.zoffy.zoffyapi.commen.IdRequest;
import com.zoffy.zoffyapi.commen.ResultUtils;
import com.zoffy.zoffyapi.constant.UserConstant;
import com.zoffy.zoffyapi.model.dto.interfaceInfo.InterfaceInfoAddRequest;
import com.zoffy.zoffyapi.model.dto.interfaceInfo.InterfaceInfoQueryRequest;
import com.zoffy.zoffyapi.model.vo.InterfaceInfoVo;
import com.zoffy.zoffyapi.service.InterfaceInfoService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/interface")
public class InterfaceInfoController {
    @Resource
    private InterfaceInfoService interfaceInfoService;

    @PostMapping("list/page/online")
    public BaseResponse<IPage<InterfaceInfoVo>> listOnlineInterfaceInfoByPage(@RequestBody InterfaceInfoQueryRequest queryRequest){

        IPage<InterfaceInfoVo> page=interfaceInfoService.listOnlineInterfaceInfoByPage(queryRequest);
        return ResultUtils.success(page);
    }
    @AuthCheck(mustRole=UserConstant.ADMIN_ROLE)
    @PostMapping("list/page/all")
    public BaseResponse<IPage<InterfaceInfoVo>> listAllInterfaceInfoByPage(@RequestBody InterfaceInfoQueryRequest queryRequest){

        IPage<InterfaceInfoVo> page=interfaceInfoService.listAllInterfaceInfoByPage(queryRequest);
        return ResultUtils.success(page);
    }
    @AuthCheck(mustRole=UserConstant.ADMIN_ROLE)
    @PostMapping
    public BaseResponse addInterfaceInfo(HttpServletRequest request,@RequestBody InterfaceInfoAddRequest addRequest){
        long id= interfaceInfoService.addInterfaceInfo(request,addRequest);
        return ResultUtils.success(id);
    }
    @AuthCheck(mustRole=UserConstant.ADMIN_ROLE)
    @DeleteMapping
    public BaseResponse deleteInterfaceInfos(HttpServletRequest request,@RequestBody InterfaceInfoVo[] interfaceInfoVos){
        boolean flag= interfaceInfoService.deleteInterfaceInfos(request,interfaceInfoVos);
        return ResultUtils.success(flag);
    }
    @AuthCheck(mustRole=UserConstant.ADMIN_ROLE)
    @PutMapping
    public BaseResponse updateInterfaceInfo(HttpServletRequest request,@RequestBody InterfaceInfoVo interfaceInfoVo){
        boolean flag= interfaceInfoService.updateInterfaceInfo(request,interfaceInfoVo);
        return ResultUtils.success(flag);
    }

    /**
     *
     * @param request HttpServletRequest
     * @param idRequest 接口id
     * @return 接口下线结果
     */
    @AuthCheck(mustRole=UserConstant.ADMIN_ROLE)
    @PostMapping("/online")
    public BaseResponse onlineInterface(HttpServletRequest request, IdRequest idRequest){
        boolean flag = interfaceInfoService.onlineInterface(request, idRequest);
        return ResultUtils.success(flag);
    }

    /**
     *
     * @param request HttpServletRequest
     * @param idRequest 接口id
     * @return 接口下线结果
     */
    @AuthCheck(mustRole=UserConstant.ADMIN_ROLE)
    @PostMapping("/offline")
    public BaseResponse offlineInterface(HttpServletRequest request, IdRequest idRequest){
        boolean flag = interfaceInfoService.offlineInterface(request, idRequest);
        return ResultUtils.success(flag);
    }
    @GetMapping("/")
    public BaseResponse getInterfaceVoById(IdRequest idRequest){
        InterfaceInfoVo interfaceInfoVo = interfaceInfoService.getInterfaceVoById(idRequest);
        return ResultUtils.success(interfaceInfoVo);
    }

}
